package searchteam.client.ui.widgets;

import java.util.ArrayList;

import searchteam.client.beansMirrors.PaperMirror;
import searchteam.client.services.SearchTeamServices;
import searchteam.client.services.SearchTeamServicesAsync;
import searchteam.client.ui.SearchTeamUI;
import searchteam.client.ui.callbacks.getAllPapersCallback;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.ListBox;

public class PaperListBox extends ListBox implements Display{
	
	private ArrayList<PaperMirror> papers;
	
	SearchTeamServicesAsync services = GWT.create(SearchTeamServices.class);
	
	public PaperListBox() {
		papers = new ArrayList<PaperMirror>();
		this.setVisibleItemCount(1);
		
		services.getAllPapers(new getAllPapersCallback(this));
	}

	public void addMirror(MirrorDisplay mirror) {
		papers.add(((PaperMirrorDisplay)mirror).getBean());
		this.addItem(mirror.getText());
	}

	public void clearMirrors() {
		papers.clear();
		this.clear();
	}

	public SearchTeamUI getMainUI() {
		return null;
	}
	
	public PaperMirror getSelectedPaper() {
		return papers.get(this.getSelectedIndex());
	}

}
